package com.cjj.paysbdemo.controller;

import com.cjj.paysbdemo.pojo.Order;
import com.cjj.paysbdemo.servlet.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import java.util.UUID;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Resource
    OrderService orderService;

    @PostMapping("add")
    public String add(Order order, Model model){
        //生成随机的订单编号
        order.setOrderNo(UUID.randomUUID().toString());


        //设置订单的一个详情
        order.setBody("充值号码:"+order.getPhone()+"充值金额:"+order.getAmount()+"元");
        //设置订单的状态
        order.setStatus(0);
        int result=orderService.add(order);
        if (result>0){
            model.addAttribute("order",order);
            return "pay";
        }
        model.addAttribute("error","下单失败");
        return "404";
    }

}
